package com.acwing.partition5;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/12/10 16:49
 */
public class AC482合唱队形 {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split("\\s+");
        int n = Integer.parseInt(s[0]);
        int[] heights = new int[n];
        s = reader.readLine().split("\\s+");
        for (int i = 0; i < n; i++) heights[i] = Integer.parseInt(s[i]);
        writer.write(String.valueOf(dynamicProgramming(heights)));
        writer.flush();
    }

    private static int dynamicProgramming(int[] heights) {
        //选出的人最少相当于就是留下的人最多
        int n = heights.length, result = 0;
        int[] dp1 = new int[n], dp2 = new int[n];
        for (int i = 0; i < n; i++) {
            dp1[i] = 1;
            for (int j = 0; j < i; j++) {
                if (heights[j] < heights[i]) dp1[i] = Math.max(dp1[i], dp1[j] + 1);
            }
        }
        for (int i = n - 1; i >= 0; i--) {
            dp2[i] = 1;
            for (int j = n - 1; j > i; j--) {
                if (heights[j] < heights[i]) dp2[i] = Math.max(dp2[i], dp2[j] + 1);
            }
        }
        for (int i = 0; i < n; i++) result = Math.max(result, dp1[i] + dp2[i] - 1);
        return n - result;
    }
}
